#region Copyright(c) 2006 ZO, All right reserved.
// -----------------------------------------------------------------------------
// Copyright(c) 2006 ZO, All right reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   1.  Redistribution of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//   2.  Redistribution in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//   3.  The name of the author may not be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// -----------------------------------------------------------------------------
#endregion


#region Using directives

using System;
using ZO.SmartCore.Core;

#endregion

namespace ZO.SmartMessenger.Plugins
{
    /// <summary>
    /// Represent a protocol plugin to support new protolcol support
    /// </summary>
    public abstract class ProtocolPlugin : BasePlugin
    {

        #region Constructors

        #endregion

        #region Destructor

        #endregion

        #region Fields
        private string _Username;

   

        private string _Password;

    
        private int _Port;


        private string _Server;

        #endregion

        #region Events
        /// <summary>
        /// Occurs when the ProtocolPlugin is Connected.
        /// </summary>
        public event EventHandler ConnectCompleted;

        /// <summary>
        /// Occurs when the ProtocolPlugin is Connecting.
        /// </summary>
        public event EventHandler Connecting;

        /// <summary>
        /// Occurs on any error in Socket.
        /// </summary>
        public event EventHandler<ExceptionEventArgs> Error;
        #endregion

        #region Operators

        #endregion

        #region Properties


        /// <summary>
        /// Gets a value indicating whether this plugin is connected to server.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this plugin is connected; otherwise, <c>false</c>.
        /// </value>
        public abstract bool Connected { get; }


        /// <summary>
        /// Gets the name of the protocol.
        /// </summary>
        /// <value>The name of the protocol.</value>
         public abstract string ProtocolName { get; }



        /// <summary>
        /// Gets or sets the username.
        /// </summary>
        /// <value>The username.</value>
        public virtual string Username
        {
            get { return _Username; }
            set { _Username = value; }
        }

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        public virtual string Password
        {
            get { return _Password; }
            set { _Password = value; }
        }

        /// <summary>
        /// Gets or sets the port.
        /// </summary>
        /// <value>The port.</value>
        public virtual int Port
        {
            get
            {
                return _Port;
            }
            set
            {
                _Port = value;
            }
        }

        /// <summary>
        /// Gets or sets the server.
        /// </summary>
        /// <value>The server.</value>
        public virtual string Server
        {
            get
            {
                return _Server;
            }
            set
            {
                _Server = value;
            }
        }


        /// <summary>
        /// Gets the type of the plugin.
        /// </summary>
        /// <value>The plugin type.</value>
        public override PluginType Type
        {
            get { return PluginType.Protocol; }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Connects to server using this protocol.
        /// </summary>
        public abstract void Connect();


        /// <summary>
        /// Disconnects to server using this protocol.
        /// </summary>
        public abstract void Disconnect();



        /// <summary>
        /// Connects to server using this protocol in async mode.
        /// </summary>
        public abstract void ConnectAsync();


        /// <summary>
        /// Raises the <see cref="ConnectCompleted"/> event. 
        /// </summary>
        protected virtual void OnConnectCompleted(EventArgs e)
        {
            if (ConnectCompleted != null)
            {
                ConnectCompleted(this, e);
            }
        } // OnConnect


        /// <summary>
        /// Raises the <see cref="Connecting"/> event. 
        /// </summary>
        protected void OnConnecting(EventArgs e)
        {
            if (Connecting != null)
            {
                Connecting(this, e);
            }
        } // OnConnect


        /// <summary>
        /// Raises the <see cref="Error"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:SmartCore.Core.ExceptionEventArgs"/> instance containing the event data.</param>
        protected virtual void OnError(ExceptionEventArgs e)
        {
            if (Error != null)
            {
                Error(this, e);
            }

        } // OnError
        #endregion
    }
}
